package cn.wolfcode.hadoop.mapreducer.wordcount;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

        public class WordCountDriver {
                public static void main(String[] args) throws Exception {
                Configuration conf = new Configuration();
        conf.set("fs.defaultFS", "hdfs://lab301:9000");
        conf.set("mapreduce.framework.name","yarn");
        conf.set("yarn.resourcemanager.hostname","lab301");
        conf.set("mapreduce.app-submission.cross-platform","true");
        conf.set("mapreduce.job.jar", "D:\\bigdata\\hadoop\\mapreducer\\target\\mapreducer-1.0.0.jar");
        System.setProperty("HADOOP_USER_NAME","root");
//        System.setProperty("hadoop.home.dir","E:\\opensource\\hadoop-2.6.1" );
        Job job = Job.getInstance(conf);

//        job.setJar("/root/wordcount.jar");
        job.setJarByClass(WordCountDriver.class);

        job.setMapperClass(WordCountMapper.class);
        job.setReducerClass(WordCountReducer.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        job.setInputFormatClass(TextInputFormat.class);
        job.setOutputFormatClass(TextOutputFormat.class);

        FileInputFormat.setInputPaths(job,new Path("/wordcount/input"));
        FileOutputFormat.setOutputPath(job,new Path("/wordcount/output"));

        boolean flag = job.waitForCompletion(true);
        System.exit(flag?0:1);
    }
}
